package ch.yiyangerp.action.register;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import ch.yiyangerp.action.IAction;
import ch.yiyangerp.model.SysUser;
import ch.yiyangerp.service.register.UserRegisterService;

@SuppressWarnings("serial")
public class RegisterAction extends ActionSupport implements IAction , ModelDriven<SysUser>{

	// 依赖入住注册用户服务。
	private UserRegisterService userRegisterService;
	// struts2 ModalDriven
	private SysUser sysUser = new SysUser();

	public String register()
	{
		if(sysUser != null)
		{
			// 判断要注册的用户是否存在
			if(userRegisterService.isThereUser(sysUser.getUserName()))
			{
				return IAction.REGISTEREXISTERROR;
			}
			else
			{
				if(userRegisterService.saveUser(sysUser) == true)
				{
					return IAction.SUCCESS;
				}
				else
				{
					return IAction.ERROR;
				}
			}
			
		}
		else
		{
			System.out.println("sysUser null");
			return IAction.ERROR;
		}
//		System.out.println(userRegisterService.saveUser(sysUser));
		
	}
	
	public UserRegisterService getUserRegisterService() {
		return userRegisterService;
	}

	public void setUserRegisterService(UserRegisterService userRegisterService) {
		this.userRegisterService = userRegisterService;
	}

	@Override
	public SysUser getModel() {
		// TODO Auto-generated method stub
		return this.sysUser;
	}
}
